<!--审核发布-->

<template>

  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>视频审核发布</span>
      </div>
    </template>
    <el-table ref="multipleTable" @selection-change="handleSelectionChange" :data="tableData" style=" width: 100%;">
      <el-table-column prop="id" label="编号" width="80px"></el-table-column>
      <el-table-column prop="name" label="文档视频名"></el-table-column>
      <el-table-column prop="type" label="文档视频类型名">
        <template slot-scope="scope">
          {{ getTypeName(scope.row.type) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" width="80px">
        <template slot-scope="scope">
          <el-button v-show="myInfo.role === '审核人员'" class="el-icon-view" type="primary" circle plain
            @click="updateInfo(scope.row.id)">
          </el-button>
          <el-button v-show="myInfo.role === '发布人员'" class="el-icon-document-checked" type="primary" circle plain
            @click="updateInfo(scope.row.id)">
          </el-button>

        </template>
      </el-table-column>
      <template #empty>
        <el-empty description="没有数据" />
      </template>
    </el-table>


    <el-pagination style="margin-top: 20px;text-align: right;" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :background="background" :current-page="currentPage" :page-sizes="[5, 10]"
      :page-size="5" layout="total, sizes, prev, pager, next, jumper" :total="totalCount">
    </el-pagination>


    <el-dialog :title="myInfo.role === '审核人员' ? '审核界面' : '发布界面'" :visible.sync="updateVisible"
      :before-close="clearForm">
      <el-form v-model="updateData">
        <el-form-item label="文件类型" :label-width="'110px'" :rules="[{ required: true }]">
          <el-select v-model="updateData.type" placeholder="请选择" style="width:100%">
            <el-option v-for="item in documentVideoTypeList" :key="item.value" :label="item.name" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="文件名" :label-width="'110px'" :rules="[{ required: true }]">
          <el-input v-model="updateData.name"></el-input>
        </el-form-item>
        <el-form-item label="">
          <!-- 使用 Element UI 的链接样式 -->
          <el-link v-if="!getDocumentOrViewType()" :href="getUrl()" target="_blank" type="primary"
            icon="el-icon-download" style="margin-left: 110px;">
            下载文档文件
          </el-link>
          <!-- 视频播放器保持不变，但是可以添加一些 Element UI 的类来改善样式 -->
          <div v-if="getDocumentOrViewType()" class="video-container">
            <video width="100%" controls class="video-element">
              <source :src="getUrl()" type="video/mp4">
              您的浏览器不支持视频标签。
            </video>
          </div>
        </el-form-item>
      </el-form>


      <div slot="footer" class="dialog-footer">
        <el-button @click="clearForm()">取 消</el-button>
        <el-button v-show="myInfo.role === '审核人员'" type="primary" @click="updateForm()">审核</el-button>
        <el-button v-show="myInfo.role === '发布人员'" type="primary" @click="updateForm()">发布</el-button>
      </div>
    </el-dialog>
  </el-card>

</template>
<script>


import {
  addDocumentVideo,
  changeDocumentVideo,
  deleteDocumentVideo,
  getAllDocumentVideo, getReviewDocumentVideoList
} from "@/api/documentVideo";
import { getDocumentVideoTypeList } from "@/api/documentVideoType";
import { getInfo } from "@/api/user";

export default {
  data() {
    return {
      background: true,
      // 每页显示的条数
      pageSize: 5,
      // 总记录数
      totalCount: 100,
      // 当前页码
      currentPage: 1,
      // 添加数据对话框是否展示的标记
      dialogVisible: false,
      // 表格数据
      tableData: [],
      documentVideo: {},
      form: {},
      posts: [],
      multipleSelection: [],
      selectedIds: [],
      documentVideoTypeList: [],
      formLabelWidth: "140px",


      //文件上传
      fileList: [],
      addOrUpdateFileList: [],//所有文件上传后的地址
      attachmentInfoShow: false,
      type: '',
      //更新
      updateVisible: false,
      updateData: {},

      myInfo: {},//操作人信息
    }
  },
  methods: {
    show() {
      let searchChoose = 0;
      if (this.myInfo.role === "发布人员") {
        searchChoose = 1;
      }
      getReviewDocumentVideoList(searchChoose, this.currentPage, this.pageSize).then((res) => {
        if (res.data.code === 1) {
          this.totalCount = res.data.data.total;
          this.tableData = res.data.data.rows;
          console.log("sss", res)
          if (this.tableData.length === 0 && this.currentPage > 1) {
            this.currentPage -= 1;
            this.show();
          }
        }
      }).catch((e) => {
      })
    },
    getDocumentVideoTypeLists() {
      getDocumentVideoTypeList().then((res) => {
        if (res.data.code === 1) {
          this.documentVideoTypeList = res.data.data;
        } else {
          this.$message.error(res.data.msg);
        }
      }).catch((e) => {
      })
    },
    getTypeName(type) {
      const types = this.documentVideoTypeList.find(t => t.id === type);
      return types ? types.name : '';
    },
    getDocumentOrViewType() {
      console.log(this.getTypeName(this.updateData.type))
      return this.getTypeName(this.updateData.type).endsWith("视频");
    },
    getUrl() {
      return this.updateData.url;
    },
    clear() {
      this.documentVideo = {};
      this.show();
    },
    add() {
      this.documentVideo = {};
      this.addOrUpdateFileList = [];
      this.type = ''
      this.dialogVisible = true;
    },
    updateForm() {
      if (this.myInfo.role === "审核人员") {
        this.updateData.status = "未发布"
      } else if (this.myInfo.role === "发布人员") {
        this.updateData.status = "已发布"
      }
      changeDocumentVideo(this.updateData).then(res => {
        //console.log(res)
        if (res.data.code === 1) {
          this.$message.success("操作成功")
          this.updateVisible = false;
          this.show()
        } else {
          this.$message.error(res.data.msg)
          this.updateVisible = false;
        }
      }).catch(e => {
      });
    },
    clearForm() {
      this.updateData = {};
      this.updateVisible = false;
    },

    close() {
      this.dialogVisible = false;
      this.type = "";
      this.addOrUpdateFileList = [];
      this.fileList = [];
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    updateInfo(id) {
      this.updateData = this.tableData.filter(data => data.id === id)[0];
      this.updateVisible = true;
    },

    //分页
    handleSizeChange(val) {
      // 重新设置每页显示的条数
      this.pageSize = val;
      this.show();
    },
    handleCurrentChange(val) {
      // 重新设置当前页码
      this.currentPage = val;
      this.show();
    },
    getMyInfo() {
      getInfo().then((res) => {
        if (res.data.code === 1) {
          this.myInfo = res.data.data;
          this.show();
        }
      }).catch((e) => {
      })
    },


  },
  mounted() {
    this.getDocumentVideoTypeLists();
    this.getMyInfo();
    this.show();
  },
};
</script>


<style>
* {
  margin: 0;
  padding: 0;
}

.el-header {
  background-color: rgb(238, 241, 246);
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: white;
}
</style>
<script setup>
</script>